var vueApp = new Vue({
  el: '#app',
  data: function () {
    return {
    	msgId:'',
    	mtpOptions:[],
    	msgType:'',    	
    	url:'recvlist.html?',
    	loading: false,
    	createDate: new Date(),
    	gsbm:'',
    	cascaderdeptOpt:{  			
    		 showallevels:true,  //false 仅显示一级  true 显示多级  	
    		 changeonselect:true,//若需要允许用户选择任意一级选项，则可将change-on-select赋值为true ; false 只能选择最后一级
    		 clearable:true,//可清除
    		 filterable:true,//将filterable赋值为true即可打开搜索功能
    		 defaultProps: {
    			children : 'children',
    			label : 'label',
    			value : 'id'
    		 },
    	},    		
    	cascaderdept:{  		    
    		 depts:[],   		  
    		 deptvalue:[], //默认值通过数组的方式指定
    	},  
    	title:'',
    	content:'',
    	fileArgs:{},
    	fdelable:false,
    	activeNames: ['1','2'],
    	comm:''
      };
  },
  mounted: function () {
	  this.init();
  },
  methods: {
	  init:function(){
		 this.detailId = tools.getQueryString("detailId");
	     this.mtpOptions.push.apply(this.mtpOptions,msg_type);
	     this.cascaderdept=tools.getDeptOpts(parseInt(userExInfo.deptCode),"0","0"); 
	     this.gsbm = userExInfo.deptCode;
	     this.getInfo();  
	     this.readInfo();
	     this.fileArgs.fileNo = this.fileNo;
		 this.fileArgs.msgId = this.msgId;  
		 this.$refs.flist.onSearch();
		 
	  },
	  readInfo:function(){
		  var that=this;
		  var jsonStr={
		   "detail_id": this.detailId
		  };
		  var reqData={
			"jsonStr":JSON.stringify(jsonStr)
		  };
		  var data = tools.ajaxRequestEx("pub/msg/userReadMsg", reqData);
		  if(data.respCode !=0){
			  that.showError(data.respDesc);   
			  return false;
		  }	
	  },
	  getInfo:function(){
		  var that=this;
		  var jsonStr={
		   "detail_id": this.detailId
		  };
		  var reqData={
			"jsonStr":JSON.stringify(jsonStr)
		  };
		  var data = tools.ajaxRequestEx("pub/msg/msgDetailInfo", reqData);
		  if(data.respCode !=0){
			  that.showError(data.respDesc);   
			  return false;
		  }else{
			  var info = data.list[0];
			  that.msgType = info.msg_type;
			  that.createDate = new Date(info.create_date.replace(/-/g,'/'));
			  that.gsbm = info.gsbm;
			  that.cascaderdept=tools.getDeptOpts(parseInt(that.gsbm),"0","0"); 
			  that.title = info.msg_title;
			  that.content = info.msg_cont;
			  that.fileNo = info.file_no;
			  that.comm = info.comm;
  	       }			      
		  
	  },	  
	  deptChg:function(value){
	  	var arry = tools.deptchange(value,this.cascaderdept.depts);
	  	this.gsbm= arry[arry.length-1];
	  },
	  check:function(){
		
		return true;
	  },
	  save:function(){		  
		  if(!this.check()){  
			  return false;
		  }		  
		  var that=this;
		  var jsonStr={
		     "detail_id": this.detailId,
		     "comm": this.comm		     
		  };
		  var reqData={
			"jsonStr":JSON.stringify(jsonStr)
		  };
		  
		  tools.ajaxRequestAsyncEx("pub/msg/userCommMsg", reqData, function(data){
		   		if(data.respCode !=0){
		   			that.showError(data.respDesc);   
		   			return false;
			    }else{
			    	that.$message({
			            showClose: true,
			            type: 'success',
			            message: "保存成功"
			        });  
			    	setTimeout(function(){
			    		that.back();
			    	},2000);			    	
  	            }			    
		   });		  
		  
		  
	  },
	  back:function(){
		 window.location.href=this.url+"msgType="+tools.getQueryString("msgType")+"&read_status="+tools.getQueryString("read_status")
		 +"&title="+tools.getQueryString("title")+"&beginDate="+tools.getQueryString("beginDate")
		 +"&endDate="+tools.getQueryString("endDate");  
	  },
     
      showError: function(info){
          var i = (info==undefined?"加载数据错误":info);
          this.$alert(i, '系统错误', {
               confirmButtonText: '确定'
          }); 
      },
    },
  watch:{
      
  }
});

